package wechat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import wechat.resources.AppFilter;
import wechat.resources.InstanceResource;
import wechat.service.impl.IDepartmentService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Controller
@RequestMapping("/department")
public class DepartmentController {

	private Logger log = LoggerFactory.getLogger(DepartmentController.class);

	@Autowired
	IDepartmentService departmentService;
	
	@RequestMapping(value = "/getDepartmentList/{appid}", method = RequestMethod.GET,produces = "application/json; charset=utf-8")
	@ResponseBody
	public String getDepartmentList(HttpServletRequest request, HttpServletResponse response,
			@PathVariable(value = "appid") String appid, 
			@RequestParam(value = "id", required = false) String id) {

		InstanceResource instanceResource = AppFilter.chooseApp(appid);
		String departmentList = "";
		try {
			departmentList = departmentService.getDepartmentList(instanceResource, id);
			log.info("DepartmentController -- getDepartmentList  departmentList=" + departmentList);
		} catch (Exception e) {
			log.error("DepartmentController -- getDepartmentList  失败", e);
			e.printStackTrace();
		}

		return departmentList;
	}

}
